using System;
using System.ComponentModel;

using DevExpress.Xpo;
using DevExpress.Data.Filtering;

using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;
using DevExpress.Xpo.Metadata;

namespace AppSolution.Module
{
    [DefaultClassOptions]
    public class TestObjectSpace : BaseObject
    {
        public TestObjectSpace(Session session)
            : base(session)
        {

        }

        public override void AfterConstruction()
        {
            base.AfterConstruction();
            CreateTime = DateTime.Now;
        }
        private string _Test1;
        [Custom("Caption", "Test1")]
        public string Test1
        {
            get { return _Test1; }
            set { SetPropertyValue<string>("Test1", ref _Test1, value); }
        }
        private DateTime _CreateTime;
        [Custom("Caption", "CreateTime")]
        [Custom("DisplayFormat", "F")]
        public DateTime CreateTime
        {
            get { return _CreateTime; }
            set { SetPropertyValue<DateTime>("CreateTime", ref _CreateTime, value); }
        }
    }
    [DefaultClassOptions]
    [DefaultProperty("Id")]
    public class TestObjectSpaceByKey : XPLiteObject
    {
        public TestObjectSpaceByKey(Session session)
            : base(session)
        {

        }
        private int _Id;
        [Custom("Caption", "Id")]
        [Key(false)]
        public int Id
        {
            get { return _Id; }
            set { SetPropertyValue<int>("Id", ref _Id, value); }
        }
    }

    //[DefaultClassOptions]
    //public class BOA : BaseObject
    //{
    //    public BOA(Session session)
    //        : base(session)
    //    {
    //        // This constructor is used when an object is loaded from a persistent storage.
    //        // Do not place any code here or place it only when the IsLoading property is false:
    //        // if (!IsLoading){
    //        //    It is now OK to place your initialization code here.
    //        // }
    //        // or as an alternative, move your initialization code into the AfterConstruction method.
    //    }
    //    public override void AfterConstruction()
    //    {
    //        base.AfterConstruction();
    //        // Place here your initialization code.
    //    }
    //    private string _Title;
    //    [Custom("Caption", "Title")]
    //    public string Title
    //    {
    //        get { return _Title; }
    //        set { SetPropertyValue<string>("Title", ref _Title, value); }
    //    }
    //    private string _MyProperty;
    //    [Custom("Caption", "MyProperty")]
    //    public string MyProperty
    //    {
    //        get
    //        {
    //            return _MyProperty;
    //        }
    //        set { SetPropertyValue<string>("MyProperty", ref _MyProperty, value); }
    //    }

    //}

    //public class MOV<T> : BaseObject
    //    //where T : class
    //{
    //    public MOV(Session session)
    //        : base(session)
    //    {

    //    }
    //    private string _MyValue;
    //    [Custom("Caption", "MyValue")]
    //    public string MyValue
    //    {
    //        get { return _MyValue; }
    //        set { SetPropertyValue<string>("MyValue", ref _MyValue, value); }
    //    }
    //    private T _MyProperty;
    //    [Custom("Caption", "MyProperty")]
    //    public T MyProperty
    //    {
    //        get { return _MyProperty; }
    //        set { SetPropertyValue<T>("MyProperty", ref _MyProperty, value); }
    //    }

    //    //[Association(Type.GetType(T)]
    //    public XPCollection XPCol
    //    {
    //        get
    //        {

    //            return GetCollection("XPCol");
    //        }
    //    }
    //}

    //public class MOGG : BaseObject
    //{
    //    public MOGG(Session session)
    //        : base(session)
    //    {

    //    }
    //    private MOV<MOGG> _TMOH;
    //    [Custom("Caption", "TMOH")]
    //    [Association(typeof(MOV<MOGG>))]
    //    public MOV<MOGG> TMOH
    //    {
    //        get { return _TMOH; }
    //        set { SetPropertyValue<MOV<MOGG>>("TMOH", ref _TMOH, value); }
    //    }

    //}

    //[DefaultClassOptions]
    //public class MOSTRING : MOV<string>
    //{
    //    public MOSTRING(Session session)
    //        : base(session)
    //    {

    //    }
    //}



    //[DefaultClassOptions]
    //public class MOINT : MOV<int>
    //{
    //    public MOINT(Session session)
    //        : base(session)
    //    {

    //    }
    //    private string _Contenct;
    //    [Custom("Caption", "Contenct")]
    //    public string Contenct
    //    {
    //        get { return _Contenct; }
    //        set { SetPropertyValue<string>("Contenct", ref _Contenct, value); }
    //    }
    //}


    //public abstract class AOA : BaseObject
    //{
    //    public AOA(Session session)
    //        : base(session)
    //    {

    //    }
    //    private string _myProperty;
    //    [Custom("Caption", "MyProperty")]
    //    public string MyProperty
    //    {
    //        get { return _myProperty; }
    //        set { SetPropertyValue<string>("MyProperty", ref _myProperty, value); }
    //    }

    //}
    //[MapInheritance(MapInheritanceType.OwnTable)]
    //public class AOB : AOA
    //{
    //    public AOB(Session session)
    //        : base(session)
    //    {

    //    }

    //    private string _MMOD;
    //    [Custom("Caption", "MMOD")]
    //    public string MMOD
    //    {
    //        get { return _MMOD; }
    //        set { SetPropertyValue<string>("MMOD", ref _MMOD, value); }
    //    }

    //}

    //public abstract class BOB : BaseObject
    //{
    //    public BOB(Session session)
    //        : base(session)
    //    {

    //    }
    //    private string _myProperty;
    //    [Custom("Caption", "MyProperty")]
    //    public string MyProperty
    //    {
    //        get { return _myProperty; }
    //        set { SetPropertyValue<string>("MyProperty", ref _myProperty, value); }
    //    }

    //}
    //[MapInheritance(MapInheritanceType.ParentTable)]
    //public class BOC : BOB
    //{
    //    public BOC(Session session)
    //        : base(session)
    //    {

    //    }
    //    private string _LOHG;
    //    [Custom("Caption", "LOHG")]
    //    public string LOHG
    //    {
    //        get { return _LOHG; }
    //        set { SetPropertyValue<string>("LOHG", ref _LOHG, value); }
    //    }


    //}
    //[MapInheritance(MapInheritanceType.OwnTable)]
    //public abstract class COC : BaseObject
    //{
    //    public COC(Session session)
    //        : base(session)
    //    {

    //    }
    //    private string _myProperty;
    //    [Custom("Caption", "MyProperty")]
    //    public string MyProperty
    //    {
    //        get { return _myProperty; }
    //        set { SetPropertyValue<string>("MyProperty", ref _myProperty, value); }
    //    }

    //}
    //public class COD : COC
    //{
    //    public COD(Session session)
    //        : base(session)
    //    {

    //    }
    //    private string _MOGGGGG;
    //    [Custom("Caption", "MOGGGGG")]
    //    public string MOGGGGG
    //    {
    //        get { return _MOGGGGG; }
    //        set { SetPropertyValue<string>("MOGGGGG", ref _MOGGGGG, value); }
    //    }


    //}

    //[MapInheritance(MapInheritanceType.ParentTable)]
    //public class AOC : AOA
    //{
    //    public AOC()
    //    {

    //    }
    //}


    [DefaultClassOptions]
    public class MUser : BaseObject
    {
        public MUser(Session se):base(se)
        {

        }
        private string regLogin;
        private DateTime regDate;

        public string Login
        {
            get { return regLogin; }
            set { SetPropertyValue<string>("Login", ref regLogin, value); }
        }
        [ValueConverter(typeof(Encryption))]
        public DateTime RegistrationDate
        {
            get { return regDate; }
            set { SetPropertyValue<DateTime>("RegistrationDate", ref regDate, value); }
        }
    }

    public class Encryption : ValueConverter
    {
        public override object ConvertToStorageType(object value)
        {
            return value.ToString();
        }
        public override object ConvertFromStorageType(object value)
        {
            return Convert.ToDateTime(value);
        }
        public override Type StorageType
        {
            get { return typeof(string); }
        }
    }

}
